<?php

namespace Modules\SmallApi\Http\Controllers;

use Cache;
use HiCommon\Service\LoginUserService;
use HiCommon\Service\WxLoginService;
use Illuminate\Support\Facades\Request;
use Modules\SmallApi\Service\LoginService;

class IndexController extends BaseController
{

    /**
     * 小程序授权登录
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function small_login_in(){
        try {
            $arr_input = Request::input();
            return LoginUserService::mini_login_in_by_jscode($arr_input);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }

    }

    /**
     * 小程序绑定手机号登录
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function mini_wx_login_bind_phone(){
        try {
            $arr_input = Request::input();
            shiwu_start();
            $result = WxLoginService::api_wx_login_bind_phone($arr_input);
            shiwu_end($result);
            return $result;
        }
        catch (\Exception $exception) {
            return hello_error('登录失败',[],$exception->getMessage());
        }

    }

    /**
     * 获取微信手机号
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function get_mini_wechat_phone(){
        $arr_input = Request::input();
        $arr_input['small_openid'] = str_trim(small_api_user_openid());
        return LoginService::get_mini_wechat_phone($arr_input);
    }

//    /**
//     * 用户名密码注册账号
//     *
//     * @return array
//     * @author wumengmeng <wu_mengmeng@foxmail.com>
//     */
//    public function username_register(){
//        $arr_input = Request::input();
//        return LoginService::register_by_username_pass($arr_input);
//    }

    /**
     * 用户名密码登录
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function username_login(){
        $arr_input = Request::input();
        return LoginService::login_in_by_username_pass($arr_input);
    }

    /**
     * 单文件上传
     */
    public function upload_one_file()
    {
        $arr_get = Request::input();
        $res = upload_one_file($_FILES["file"],$arr_get);
        return $res;
    }

//
//    public function get_openid(){
//        $s_jscode = Request::input('code');
//        return LoginService::get_small_openid_by_code($s_jscode);
//
//    }

}